home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / RANDBRD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  1.5 KB  |  45 lines

  1. /* RANDBRD.C --- p. 652 */
  2. #include <stdio.h>
  3. #include <dos.h>
  4. #define FCB_OPEN 0x0f
  5. main()
  6. {
  7.     char input[80], buffer[256], far *old_dta;
  8.     int option;                /* Option for parsfnm */
  9.     struct fcb fcb;                /* File Control Block, FCB */
  10.     int i, result;
  11.     printf("Enter name of file from which we will "
  12.            "read tow 128-byle records:\n(only drive and file "
  13.            "name allowed, for example, A:MYFILE.DAT):");
  14.     gets(input);
  15.             /* parse file name using 'parsfnm' and an FCB */
  16.     option = 1;        /* means skip leading separators  */
  17.     parsfnm(input, &fcb, option);
  18.     printf("Reading from \nDrive number: %d\n File name:      %s\n",
  19.                         fcb.fcb_drive, fcb.fcb_name);
  20.             /* Now open the file using DOS function 0fh (this
  21.              * is not the same as "_open" which uses handles */
  22.     if(bdosptr(FCB_OPEN, &fcb, 0) == -1)
  23.     {
  24.         printf("File open error\n");
  25.         exit(1);
  26.     }
  27.             /* Save current disk transfer address and set up a
  28.              * new one with enough room for data being read. */
  29.     old_dta = getdta();
  30.     setdta(buffer);
  31.             /* Now set up the record size and start block */
  32.     fcb.fcb_recsize = 128;
  33.     fcb.fcb_random = 0L;            /* start at record 0 */
  34.     result = randbrd(&fcb, 2);
  35.     printf("result = %d\n", result);
  36.     if(result == 0) printf("Read ok\n");
  37.     if(result == 1 || result == 3)
  38.         printf("File ended during read\n");
  39.             /* Print data read (assume ASCII text data)  */
  40.     printf("The first 26 characters are:\n");
  41.     for(i = 0; i < 256; i++)
  42.         putchar(buffer[i]);
  43.                     /* Reset DTA to old value  */
  44.     setdta(old_dta);
  45. }